/* $Id:job.h $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#ifndef __JOB_H
#define __JOB_H

#include <string>
#include <map>
#include <list>
using namespace std;

#include "material.h"

#define loopJobSpecial(r,v) loopSingle((r)->listSpecial(),v,class material,list)

class job {
    string name;
    string description;
    map<string,class material> special;
    int status;
public:
    job();

    // Field : name
    const string getName() const;
    void setName(const string v);

    // Field : description
    const string getDescription() const;
    void setDescription(const string v);

    // Field : special
    class material& getSpecial(const string v);
    list<class material>& listSpecial();
    void setSpecial(class material &v);
    void delSpecial(const string v);
    const bool isSpecial(const string v) const;

    // Field : status
    const int getStatus() const;
    void setStatus(const int v);

    void save(class channel &ch);
    void load(class channel &ch);
    void xml(ofstream &f, int l=0, int r=0);
};

// Repository

#define loopJobs(v) loopMap(job_repo.listJob(),v,class job)

class jobRepository {
    map<string,job> jobs;
public:
    class job& getJob(const string v);
    void setJob(class job& v);
    map<string,class job>& listJob();
    void delJob(const string v);
    const bool isJob(const string v) const;
    multimap<string, sigc::signal<void, class job& > > relations;
    bool load(class channel &ch);
    void save(class channel &ch);
};

extern jobRepository job_repo;

#endif // __JOB_H
